package com.sl.shiro;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class RolesFilter extends AuthorizationFilter {

    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) {
        Subject subject = this.getSubject(servletRequest,servletResponse);
        String roles[] = (String[]) o;
        for (String role:roles){
            if (subject.hasRole(role))
            {return true;}
        }
        return false;
    }

}
